runOnStartup(async runtime => {
    runtime.addEventListener("tick", () => tick())
    runtime.getLayout("MainLevel").addEventListener("afterlayoutstart", () => init())
});
function tick() {
    if (runtime.layout.name != "MainLevel") return;
    AnimationPlayer.AnimationPlayerChange()
}
function init() {
    AnimationPlayer.init()
}
globalThis.AnimationPlayer = {
    init: function () {
        /**@type {I8DirectionBehaviorInstance} */
        this.playerMovebehavior = this.PlayerCollisionInstanceMoveBehavior = runtime.objects.PlayerCollision.getFirstInstance().behaviors['8Direction']
        /**@type {ISpriteInstance} */
        this.playerAmimationTakeBy = runtime.objects.PlayerAnimations.getFirstInstance()
        /** @type {I3DShapeInstance} */
        this.playerboard = runtime.objects.PlayerBillboard.getFirstInstance()
    },
    AnimationPlayerChange: function () {
        /** @type {I3DShapeInstance} */
        let pb = this.playerboard
        /**@type {ISpriteInstance} */
        let animation = this.playerAmimationTakeBy
        if (pb.zElevation > 1) {
            animation.setAnimation("Jump")
        }
        if (this.playerMovebehavior.speed > 3 && pb.zElevation <= 1) {
            animation.setAnimation("Walk")
        }
        if (this.playerMovebehavior.speed < 3 && pb.zElevation <= 1) {
            animation.setAnimation("Idle")
        }
    },
}
export default AnimationPlayer